﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Speech.Synthesis;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DGRobot
{
    public partial class ConfigFrm : Form
    {
        public ConfigFrm()
        {
            InitializeComponent();
        }

        class VoiceName
        {
            public string Name { get; set; }
            public string Id { get; set; }
        }
        private void ConfigFrm_Load(object sender, EventArgs e)
        {
            SpeechSynthesizer synth = new SpeechSynthesizer();
            var voices  = synth.GetInstalledVoices(new CultureInfo("zh-CN"));
            var list = new List<object>();
            foreach (var voice in voices)
            {
                if(voice.Enabled ==false)continue;
                list.Add(
                    new VoiceName
                    {
                        Name = string.Format("[{0}] {1}", voice.VoiceInfo.Gender, voice.VoiceInfo.Name),
                        Id = voice.VoiceInfo.Name
                    });
            }
            this.cmbTTS.DataSource = list;
            this.cmbTTS.DisplayMember = "Name";
            
            this.txtApiUrl.Text = Config.NlpServerUrl;
            this.txtWakeupWord.Text = Config.WakeupWord;
            this.chkIsDebug.Checked = Config.IsDebug;


            this.txtTbmServerUrl.Text = Config.TbmServerUrl;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Config.NlpServerUrl = this.txtApiUrl.Text;
            Config.WakeupWord = this.txtWakeupWord.Text;
            Config.TbmServerUrl = this.txtTbmServerUrl.Text;
            Config.IsDebug = this.chkIsDebug.Checked;
            Config.TTSName = ((VoiceName)this.cmbTTS.SelectedValue).Id;
            Config.Save();

            RobotDriver.Instance.ChangeVoice(Config.TTSName);
            
            this.Close();
        }
    }
}
